<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // ES6中新增剩余参数，形式为:...形参，用于获取多余的参数
        function f1(...nums){
            console.log(nums);
        }
        f1();
        f1(20,30,40);

        // 剩余参数必须是最后一个参数，否则会报错
        function f2(a,...b){
            console.log(a);
            console.log(b);
        }
        f2(100,200,300,"a","b");

        // 有了剩余参数rest，可以代替刚刚计算实参的和

        function calcSum(...m){
            var sum=0;
            for(var i=0;i<m.length;i++){
                sum+=m[i];
            }
            return sum;
        }
        console.log(calcSum(100,200,300,400));
        console.log(calcSum(1000,2000,3000,900,1000));
    </script>
</head>
<body>
    
</body>
</html>